package org.ysh.listener;

import org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext;
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

import javax.servlet.ServletContext;

/**
 * 注册系统缓存
 */
@Component
public class SysFuncCacheListener implements ApplicationListener<ContextRefreshedEvent> {
    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        if(contextRefreshedEvent.getApplicationContext() instanceof AnnotationConfigServletWebServerApplicationContext){
            AnnotationConfigServletWebServerApplicationContext context = (AnnotationConfigServletWebServerApplicationContext) contextRefreshedEvent.getApplicationContext();
            // 获取servlet上下文
            ServletContext servletContext = context.getServletContext();
            //后面从系统参数中获取
            assert servletContext != null;
            servletContext.setAttribute("sysName","智慧档案管理系统");
            servletContext.setAttribute("sysVersion","v1.0");
            servletContext.setAttribute("sysLogo","/publish/images/logoIndex.jpeg");
        }

    }
}
